home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
55375
/
55375.xpi
/
chrome
/
chromeFiles
/
content
/
btOverlay.xul
< prev
next >
Wrap
Extensible Markup Language
|
2009-11-15
|
13KB
|
357 lines
<?xml version="1.0"?>
<!DOCTYPE btClient SYSTEM "../locale/btClient.dtd">
<overlay
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript;version=1.7" src="btClient.js" />
<script type="application/x-javascript;version=1.7" src="btUtilities.js" />
<script type="application/x-javascript;version=1.7" src="sc_refinements.js" />
<script type="application/x-javascript;version=1.7">
(function (brandObject) {
BrandThunder.initialize(brandObject);
for (var client in BrandThunder.clients) {
var clientUtils = BrandThunder.clients[client].utilities;
if (clientUtils) {
if (clientUtils.initializeButtons) {
for (func in clientUtils) {
if (brandObject.utilities[func]) {
clientUtils[func] = brandObject.utilities[func];
}
}
}
}
}
var prefObserver = {
observe: function observe(subject, topic, data) {
switch (data) {
case "currentBoom":
brandObject.utilities.switchBoom(brandObject, true);
break;
case "bigBoom":
brandObject.utilities.toggleTheme(brandObject);
break;
}
}
}
var btObserver = {
observe: function observe(subject, topic, data) {
switch (topic) {
case "lightweight-theme-changed":
if (data == "null") {
btPrefBranch.setBoolPref("bigBoom", true);
} else {
btPrefBranch.setBoolPref("bigBoom", false);
}
break;
}
}
}
var btPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.brandthunder.");
btPrefBranch.QueryInterface(Components.interfaces.nsIPrefBranch2);
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var yahooTabSearchHTML;
var askTabSearchHTML;
var xhr = new XMLHttpRequest();
xhr.open('GET', "http://brandthunder.com/yahoo/tab_search.html", true);
xhr.onload = function() {
yahooTabSearchHTML = xhr.responseText;
}
xhr.send(null);
var xhr2 = new XMLHttpRequest();
xhr2.open('GET', "http://brandthunder.com/ask/tab_search.html", true);
xhr2.onload = function() {
askTabSearchHTML = xhr2.responseText;
}
xhr2.send(null);
var xhr3 = new XMLHttpRequest();
xhr3.open('GET', "http://brandthunder.com/bing/tab_search.html", true);
xhr3.onload = function() {
bingTabSearchHTML = xhr3.responseText;
}
xhr3.send(null);
function tabOpen(event) {
var browser = gBrowser.getBrowserForTab(event.originalTarget);
if (browser.contentDocument.location.href != "about:blank") {
return;
}
function blankTabSearchTimeout(inner_event) {
var doc = inner_event.target;
browser.removeEventListener("DOMContentLoaded", blankTabSearchTimeout, false);
window.setTimeout(blankTabSearch, 250, doc);
}
browser.addEventListener("DOMContentLoaded", blankTabSearchTimeout, false);
}
function blankTabSearch(doc) {
try {
var tabSearch = btPrefBranch.getBoolPref("tabSearch");
if (!tabSearch) {
return;
}
} catch (ex) {
}
var currentBoom = btPrefBranch.getCharPref("currentBoom");
/* Only handle tab requests for our boom */
if (!brandObject.booms[currentBoom]) {
return;
}
/* Find the client that corresponds to the current boom */
var boomClient;
for (let i in BrandThunder.clients) {
for (let j in BrandThunder.clients[i].booms) {
if (j == currentBoom) {
boomClient = i;
break;
}
}
}
if (!doc) {
return;
}
var body = doc.getElementsByTagName("body")[0];
if (!body || body.innerHTML != '') {
return;
}
html = doc.getElementsByTagName("html")[0];
var currentEngine = searchSvc.currentEngine.description;
if ((currentEngine != "Ask - BT") &&
(currentEngine != "Yahoo! - BT")) {
currentEngine = brandObject.defaultSearchEngine;
}
function askTabSearch() {
if (askTabSearchHTML) {
html.innerHTML = askTabSearchHTML;
var oElement = doc.getElementById("o");
/* Get the current boom */
var askCode;
if (boomClient) {
askCode = BrandThunder.clients[boomClient].askOriginCode;
} else {
askCode = brandObject.askOriginCode;
}
oElement.setAttribute("value", askCode);
}
}
function yahooTabSearch() {
if (yahooTabSearchHTML) {
html.innerHTML = yahooTabSearchHTML;
var typeElement = doc.getElementById("type");
/* Get the current boom */
var type;
if (boomClient) {
type = BrandThunder.clients[boomClient].releaseIdentifier;
} else {
type = brandObject.releaseIdentifier;
}
typeElement.setAttribute("value", type);
}
}
function bingTabSearch() {
if (bingTabSearchHTML) {
html.innerHTML = bingTabSearchHTML;
}
}
switch (currentEngine) {
case "Ask - BT":
askTabSearch();
break;
case "Yahoo! - BT":
yahooTabSearch();
break;
case "Bing - BT":
bingTabSearch();
break;
}
function setPreference(event) {
btPrefBranch.setBoolPref("tabSearch", !event.target.checked);
}
if (askTabSearchHTML || yahooTabSearchHTML) {
var tabSearchPref = doc.getElementById("tabSearchPref");
if (tabSearchPref) {
tabSearchPref.style.display = "";
tabSearchPref.addEventListener("click", setPreference, false);
}
}
}
function navBarEvent(event) {
if (event.button == 0) {
var currentBoom = btPrefBranch.getCharPref("currentBoom");
if (!brandObject.booms[currentBoom]) {
return;
}
var targetIDLeft = "navigator-toolbox";
var targetIDRight = "navigator-toolbox";
var navBar = document.getElementById("nav-bar");
var mainWindow = document.getElementById("main-window");
var navigatorToolbox = document.getElementById("navigator-toolbox");
var navBarStyle = window.getComputedStyle(navBar,null);
var marginLeft = parseInt(navBarStyle.getPropertyValue("margin-left"));
var marginRight = parseInt(navBarStyle.getPropertyValue("margin-right"));
/* If there is no margin, use padding. This is for booms that use nav-bar padding for image */
if (marginLeft == 0) {
marginLeft = parseInt(navBarStyle.getPropertyValue("padding-left"));
targetIDLeft = "nav-bar";
}
if (marginRight == 0) {
marginRight = parseInt(navBarStyle.getPropertyValue("padding-right"));
targetIDRight = "nav-bar";
}
if (event.clientX < marginLeft) {
if (event.target.id == targetIDLeft) {
if (mainWindow.hasAttribute("btURLLeft")) {
if (event.type == "click") {
var subject = {};
subject.wrappedJSObject = brandObject;
observerService.notifyObservers(subject, "brandthunder", "bt-logo");
brandObject.utilities.openLink(brandObject, event, mainWindow.getAttribute("btURLLeft"));
} else if (event.type == "mousemove") {
event.target.style.cursor = "pointer";
}
}
}
} else if (event.clientX > (window.innerWidth - marginRight)) {
if ((event.target.id == targetIDRight) || (event.target.id == "toolbar-menubar")) {
if (brandObject.adURL) {
if (event.type == "click") {
brandObject.utilities.openLink(brandObject, event, brandObject.adURL);
} else if (event.type == "mousemove") {
event.target.style.cursor = "pointer";
}
}
}
} else if (event.type == "mousemove") {
event.target.style.cursor = "";
}
}
}
function navBarMouseOut(event) {
event.target.style.cursor = "";
}
function firstRun() {
brandObject.utilities.firstRun(brandObject);
function btEvent(event) {
if (event.target.ownerDocument.location.href.match(brandObject.welcomePage)) {
/* Handle search here */
if (event.target.hasAttribute("bt-search")) {
if (event.target.getAttribute("bt-search") == "true") {
brandObject.utilities.setDefaultSearchEngine(brandObject, true);
} else if (event.target.getAttribute("bt-search") == "false") {
/* Undo our prefs here */
/* We don't mess with search engines because they don't have one */
/* of ours set or they wouldn't have seen the dialog at all */
btPrefBranch.setBoolPref("keywordSearch", false);
btPrefBranch.setBoolPref("tabSearch", false);
}
}
if (brandObject.firstrun) {
brandObject.firstrun(event, brandObject);
}
}
}
window.addEventListener("BrandThunderEvent", btEvent, false, true);
try {
btPrefBranch.addObserver("", prefObserver, false);
} catch (ex) {
}
var osString = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULRuntime).OS;
var mainWindow = document.getElementById("main-window");
mainWindow.setAttribute("btPlatform", osString);
brandObject.utilities.toggleTheme(brandObject);
brandObject.utilities.switchBoom(brandObject, false);
window.removeEventListener("load", firstRun, true);
gBrowser.addEventListener("TabOpen", tabOpen, false);
document.getElementById("navigator-toolbox").addEventListener("click", navBarEvent, false);
document.getElementById("navigator-toolbox").addEventListener("mousemove", navBarEvent, false);
document.getElementById("navigator-toolbox").addEventListener("mouseout", navBarMouseOut, false);
observerService.addObserver(btObserver, "lightweight-theme-changed", false);
var currentBoom = btPrefBranch.getCharPref("currentBoom");
if (brandObject.booms[currentBoom]) {
var btClientPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.brandthunder." + brandObject.clientCode + ".");
var lastsent = 0;
try {
lastsent = btClientPrefBranch.getIntPref("btMetricsLite.lastsent");
} catch (ex) {}
var currentdate = new Date();
var currenttimestamp = currentdate.getTime() / 1000;
if (lastsent > 0) {
if ((currenttimestamp - lastsent) < 3600) {
var env = Cc['@mozilla.org/process/environment;1'].getService(Ci.nsIEnvironment);
if (!env.get('BRANDTHUNDER')) {
return;
}
}
}
btClientPrefBranch.setIntPref("btMetricsLite.lastsent", currenttimestamp);
var subject = {};
subject.wrappedJSObject = brandObject;
try {
var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefbranch.clearUserPref("extensions.btMetricsLite.lastsent");
} catch (ex) {}
observerService.notifyObservers(subject, "brandthunder", "active");
}
}
function lastRun(event) {
btPrefBranch.removeObserver("", prefObserver);
gBrowser.removeEventListener("TabOpen", tabOpen, false);
document.getElementById("navigator-toolbox").removeEventListener("click", navBarEvent, false);
document.getElementById("navigator-toolbox").removeEventListener("mousemove", navBarEvent, false);
document.getElementById("navigator-toolbox").removeEventListener("mouseout", navBarMouseOut, false);
observerService.removeObserver(btObserver, "lightweight-theme-changed", false);
window.removeEventListener("unload", lastRun, false);
}
window.addEventListener("load", firstRun, false);
window.addEventListener("unload", lastRun, false);
})(BrandThunder.clients["&btClient;"]);
</script>
<stringbundleset id="stringbundleset">
<stringbundle id="btClientBundle_&btClient;"
src="chrome://&btClient;boom/locale/btClient.properties"/>
</stringbundleset>
</overlay>